<template>
  <div class="news">
    <!--    <div class="leftMenu"-->
    <!--         v-if="menuList.length">-->
    <!--      <span @click="handlerClick(index)"-->
    <!--            :class="[{active:index==activeIndex}]"-->
    <!--            v-for="(item,index) in menuList"-->
    <!--            :key="index">{{item.colName}}</span>-->
    <!--    </div>-->
    <newsLisftMenu class="left" @handlerClick="handlerClick"></newsLisftMenu>

    <div class="rightContent">
      <div class="top">
        <img src="../../assets/location.png">
        您当前所在位置：{{parentCol}} > {{colName}}
      </div>
      <Iframe height="100%"
              :src="url"
              v-if="url"></iframe>
      <template v-else>
        <div class="content"
             v-show="show== 'list'">
          <div class="list">
            <div class="item flex-b"
                 v-for="(item,index) in artList"
                 :key="index"
                 @click="toDetail(item)">
              <div class="title flex-b">
                <img src="../../assets/square.png"
                     alt="">
                <div class="totop"
                     v-if="item.top">置顶</div>
                <div>{{item.title}}</div>
              </div>
              <div class="date">{{item.createdTime?item.createdTime.substring(0,10):''}}</div>
            </div>
          </div>
          <el-pagination v-if="total>10"
                         background
                         layout="prev, pager, next"
                         :page-size='10'
                         :total="total"
                         @current-change="currentChange">
          </el-pagination>
        </div>
        <div class="detail"
             v-show="show =='detail'">
          <detail @closeClick="show='list'"
                  ref="detail"></detail>
        </div>
      </template>

    </div>
  </div>
</template>

<script>
import detail from './detail.vue'
import newsLisftMenu from '@/components/newsLisftMenu'
export default {
  name: '',
  components: { detail, newsLisftMenu },
  data() {
    return {
      menuList: [],
      artList: [],
      activeIndex: 0,
      show: 'list',
      condition: {
        page: 0,
        pageSize: 99,
        parentId: '14',
      },
      condition2: {
        col: null,
        page: 0,
        pageSize: 10,
        category: 0,
      },
      total: 0,
      parentCol: '',
      colName: '',
      url: '',
    }
  },

  methods: {
    handlerClick(e) {
      this.condition2.col = e.columnId
      this.$router.push({ name: 'newsList', query: { columnId: e.columnId } })
    },
    toDetail(item) {
      let {href} = this.$router.resolve({name:'detail',query:{id:item.id}})
      window.open(href,'_blank')
    },
    async getColumnInfoList() {
      await this.$api.getColumnInfoList(this.condition).then((res) => {
        this.menuList = res.data.data
      })
    },
    paginHome() {
      this.$api.paginHome(this.condition2).then((res) => {
        this.artList = res.data.data
        this.total = res.data.recordsTotal
        this.getColumnInfoTreeById()
      })
    },
    currentChange(e) {
      this.condition2.page = e - 1
      this.paginHome()
    },
    getColumnInfoTreeById() {
      this.$api
        .getColumnInfoTreeById({ columnId: this.condition2.col })
        .then((res) => {
          this.parentCol = res.data.parentCol
          this.colName = res.data.colName
          this.url = res.data.url
        })
    },
  },

  computed: {},
  watch: {
    // 解决路由跳转同一个页面，携带不同参数，页面不刷新问题
    $route(to, from) {
      this.paginHome()
      // 在此处放置你create里的内容（或者mounted里面的内容）
    },
  },
  async mounted() {
    //this.condition.parentId = this.$route.query.id
    this.parentCol = this.$route.query.parentCol
    this.colName = this.$route.query.colName
    this.condition2.col = this.$route.query.columnId

    // let isThirdNode = this.menuList[0].isThirdNode
    // if (this.menuList.length == 0) {
    //   this.condition2.col = this.$route.query.id
    // } else {
    //   if (isThirdNode == '1') {
    //     this.condition2.category = this.menuList[0].id
    //   } else {
    //     this.condition2.col = this.menuList[0].id
    //   }
    // }
    this.paginHome()
  },
}
</script>
<style lang='less' scoped>
.news {
  height: 100%;
  display: flex;
}
.left{
  flex-shrink: 0;
}
.leftMenu {
  height: 100%;
  background-color: white;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 10px;
  span {
    white-space: nowrap;
    font-size: var(--font-size);
    color: #303860;
    border-radius: 16px;
    padding: 6px 12px;
    margin-top: 20px;
    cursor: pointer;
    transition: all 0.3s;
    &:hover {
      color: white;
      background-color: #3772ff;
    }
  }
  .active {
    color: white;
    background-color: #3772ff;
  }
}
.rightContent {
  margin: 10px;
  flex-grow: 1;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  .top {
    display: flex;
    align-items: center;
    font-size: 16px;
    //font-size: 12px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: #333333;
    margin-bottom: 10px;
    img {
      margin-right: 10px;
    }
  }
  .content {
    background: #ffffff;
    border-radius: 8px;
    flex: 1;
    //overflow: hidden;
    padding: 0 22px;
    .item {
      transition: all 0.3s;
      line-height: 55px;
      border-bottom: 1px solid #f5f5f5;
      font-size: var(--font-size);
      //font-size: 14px;
      font-family: Microsoft YaHei;
      font-weight: 400;
      color: #333333;
      padding: 5px 0;
      &:hover {
        cursor: pointer;
        color: #377eff;
      }
      img {
        width: 10px;
        margin-right: 10px;
      }
      .date {
        color: #999999;
      }
      .totop {
        width: 50px;
        height: 26px;
        text-align: center;
        line-height: 26px;
        background: #3772ff;
        border-radius: 4px;
        color: white;
        margin-right: 10px;
      }
    }
  }
}
.el-pagination {
  text-align: center;
  margin-top: 30px;
  margin-bottom: 10px;
  transform: scale(1.2);
}
</style>
